package com.huluobo.a2206koltindouyin.home

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.huluobo.a2206koltindouyin.R
import com.huluobo.a2206koltindouyin.adapter.NewsAdapter
import com.huluobo.a2206koltindouyin.databinding.FragmentCommonBinding
import com.huluobo.base.mvvm.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class CommonFragment(val typeId: Int) : BaseFragment<FragmentCommonBinding, HomeViewModel>() {
    private lateinit var newsAdapter: NewsAdapter
    override fun initData() {
        vm.getNewsList(1, 10, typeId)
        vm.getNewsListSuccess.observe(this) {
            newsAdapter.data.clear()
            newsAdapter.data.addAll(it)
            newsAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.itemCommonRv.layoutManager = LinearLayoutManager(requireContext())
        newsAdapter = NewsAdapter()
        binding.itemCommonRv.adapter = newsAdapter
    }
}